package com.example.ivos.application.controller;

import com.example.ivos.application.pojo.dto.ApplicationParam;
import com.example.ivos.application.pojo.dto.ApplicationQuery;
import com.example.ivos.application.pojo.vo.ApplicationVO;
import com.example.ivos.application.service.ApplicationService;
import com.example.ivos.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "申请模块")
@RestController
@Slf4j
@RequestMapping("/v1/application/")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    @ApiOperation("申请单管理")
    @PostMapping("save")
    public JsonResult save(ApplicationParam applicationParam){
        log.debug("申请单信息applicationParam:{}", applicationParam);
        applicationService.save(applicationParam);
        return JsonResult.ok();
    }

    @ApiOperation("撤销申请单")
    @PostMapping("cancel")
    public JsonResult cancel(ApplicationParam applicationParam){
        log.debug("更新申请单applicationParam:{}", applicationParam);
        applicationService.cancel(applicationParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询申请单")
    @GetMapping("select")
    public JsonResult select(ApplicationQuery applicationQuery){
        log.debug("查询申请单applicationQuery:{}",applicationQuery);
        List<ApplicationVO> list=applicationService.select(applicationQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("车辆申请")
    @PostMapping("update")
    public JsonResult update(ApplicationParam applicationParam){
        log.debug("更新申请单applicationParam:{}", applicationParam);
        applicationService.update(applicationParam);
        return JsonResult.ok();
    }
}
